package com.study.string;
/*
 *练习题：使用String完成随机生成5位的验证码。
 *
 */

import java.util.Random;

public class StringExec7 {

        public static void main(String[] args) {
            // 1.定义可能出现的字符信息
            String data1 = "abcdefghijklmnopqrstuvwxyz";
            String data2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            String data3 = "0123456789";
            System.out.println(data1.length()+","+data2.length()+","+data3.length());
            String data4 = data1+data2+data3;
            System.out.println(data4);
            // 2.循环5次，每次生成一个随机的索引，提取相对应的字符连接成串
            String code = "";
            Random rd = new Random();
            for (int i = 0; i < 5; i++) {
                int index = rd.nextInt(data4.length());
                code  += data4.charAt(index);
            }
            // 3.输出验证码
            System.out.println(code);
        }
}
